-- kill_get_item2
-- created by dengc
-- 使用道具击杀敌人概率获得物品奖励

return {
    apply = function(prop, baseValue)
        return prop[3];
    end,

    -- 触发
    trigger = function(who, prop, arg)
        local propertyId = arg["class_id"];
        if type(propertyId) ~= "number" then
            return;
        end

        local target = arg["target"];

        -- 不是期望的道具
        if prop[2] ~= propertyId then
            return;
        end

        -- 概率触发
        if DungeonM.getRandSeed("kill_get_item") % 1000 >= prop[3] then
            return;
        end

        -- 随机一种奖励
        local classId = FormulaM.invoke("FETCH_PROP_RANDOM_BONUS", propertyId);
        if type(classId) ~= "number" then
            return;
        end

        -- 目前只支持给1个
        local bonus = {1, tonumber(classId), 1};
        BonusM.doBonus(bonus, "kill_get_item2");

        -- 抛出通用建筑奖励事件
        EventMgr.fire(event.COMM_BUILDING_BONUS, {
            ["pos"]   = target:getPos(),
            ["type"]  = GRID_TYPE_MONSTER,
            ["bonus"] = { ["bonus"] = bonus },
            ["remainGrid"] = true,
        });
    end,

    record = function(target, prop, path)
        return false;
    end
};
